import T_CONFIG from "./Config";
import DataMgr from "./DataMgr"
var htmlStr = '\
  <head>\
  <meta http-equiv="refresh" content="0;URL=/admin">\
  </head>\
';

export default (req, res) => {
  let tQuery=req.query;
  if(tQuery.Type=="INIT"){
    if(!global.inited){
      global.inited=true;
      DataMgr.Instance.Init(T_CONFIG);
      setTimeout(() => {
        DataMgr.Instance.Start();
      }, 5000);
      res.send(htmlStr)
    }else{
      res.send(htmlStr)
    }
    return;
  }else if(tQuery.Type=="CLEAR"){
    DataMgr.Instance.Clear();
    DataMgr.Instance.Init(T_CONFIG)
    res.send(htmlStr)
    return;
  }else if(tQuery.Type=="REFRESH"){
    DataMgr.Instance.Init(T_CONFIG)
    setTimeout(() => {
      DataMgr.Instance.Start();
    }, 5000);
    res.send(htmlStr)
    return;
  }else if(tQuery.Type=="CHECK"){
    let tData={}
    let sHtml="<body>"
    for(let i in global.FILE){
      sHtml+=`<p>${i+"=true"}</p>`
    }
    sHtml+="</body>"
    res.send(sHtml);
    return;
  }
  let tBody = req.body
  if(!tBody){
    res.send({status:"failed"})
    return;
  }
  let tAllData=DataMgr.Instance.GetDateAllData(tBody.Date);
  res.send({status:"success",data:tAllData});
}